package com.ruoyi.service.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.service.domain.ServicePrice;
import com.ruoyi.service.service.IServicePriceService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 耗材价格调整Controller
 * 
 * @author ZDL
 * @date 2024-10-21
 */
@RestController
@RequestMapping("/service/price")
public class ServicePriceController extends BaseController
{
    @Autowired
    private IServicePriceService servicePriceService;

    /**
     * 查询耗材价格调整列表
     */
    @PreAuthorize("@ss.hasPermi('service:price:list')")
    @GetMapping("/list")
    public TableDataInfo list(ServicePrice servicePrice)
    {
        startPage();
        List<ServicePrice> list = servicePriceService.selectServicePriceList(servicePrice);
        return getDataTable(list);
    }

    /**
     * 导出耗材价格调整列表
     */
    @PreAuthorize("@ss.hasPermi('service:price:export')")
    @Log(title = "耗材价格调整", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ServicePrice servicePrice)
    {
        List<ServicePrice> list = servicePriceService.selectServicePriceList(servicePrice);
        ExcelUtil<ServicePrice> util = new ExcelUtil<ServicePrice>(ServicePrice.class);
        util.exportExcel(response, list, "耗材价格调整数据");
    }

    /**
     * 获取耗材价格调整详细信息
     */
    @PreAuthorize("@ss.hasPermi('service:price:query')")
    @GetMapping(value = "/{priceId}")
    public AjaxResult getInfo(@PathVariable("priceId") Long priceId)
    {
        return success(servicePriceService.selectServicePriceByPriceId(priceId));
    }

    /**
     * 新增耗材价格调整
     */
    @PreAuthorize("@ss.hasPermi('service:price:add')")
    @Log(title = "耗材价格调整", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ServicePrice servicePrice)
    {
        return toAjax(servicePriceService.insertServicePrice(servicePrice));
    }

    /**
     * 修改耗材价格调整
     */
    @PreAuthorize("@ss.hasPermi('service:price:edit')")
    @Log(title = "耗材价格调整", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ServicePrice servicePrice)
    {
        return toAjax(servicePriceService.updateServicePrice(servicePrice));
    }

    /**
     * 删除耗材价格调整
     */
    @PreAuthorize("@ss.hasPermi('service:price:remove')")
    @Log(title = "耗材价格调整", businessType = BusinessType.DELETE)
	@DeleteMapping("/{priceIds}")
    public AjaxResult remove(@PathVariable Long[] priceIds)
    {
        return toAjax(servicePriceService.deleteServicePriceByPriceIds(priceIds));
    }
}
